package com.android.wlw_local;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;


import org.greenrobot.eventbus.EventBus;

/**
 * Created by zhuqin on 2018/3/19.
 */

public class ControlActivity extends FragmentActivity{

    private SeekBar speedSb ;
    private Button speedVCiBtn;

    private SeekBar windSpeedSb ;
    private Button windSpeedBtn;

    private SeekBar hotSb ;
    private Button hotValueBtn;

    private SeekBar PenTouSb ;
    private Button PenTouBtn;

    private SeekBar PenTou2Sb ;
    private Button PenTou2Btn;

    private SeekBar brightSb ;
    private Button brightBtn;

    private SeekBar bright2Sb ;
    private Button bright2Btn;

    private String speed = "M220S";
    private String windSpeed ="M106S";
    private String hot ="M140S";
    private String penTou = "M104T0S";
    private String penTou2 = "M104T1S" ;
    private String bright = "M777T0S";
    private String bright2 = "M777T1S";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_control);
        initView();
        initData();
        initAction();
    }

    private void initView(){
        speedSb = (SeekBar) findViewById(R.id.speedSb);
        speedVCiBtn = (Button) findViewById(R.id.speedVCiBtn);

        windSpeedSb = (SeekBar) findViewById(R.id.windSpeedSb);
        windSpeedBtn = (Button) findViewById(R.id.windSpeedVBtn);

        hotSb = (SeekBar) findViewById(R.id.hotSb);
        hotValueBtn = (Button) findViewById(R.id.hotValueBtn);

        PenTouSb = (SeekBar) findViewById(R.id.PenTouSb);
        PenTouBtn = (Button) findViewById(R.id.PenTouBtn);

        PenTou2Sb = (SeekBar) findViewById(R.id.PenTou2Sb);
        PenTou2Btn = (Button) findViewById(R.id.PenTou2Btn);

        brightSb = (SeekBar) findViewById(R.id.brightSb);
        brightBtn = (Button) findViewById(R.id.brightBtn);

        bright2Sb = (SeekBar) findViewById(R.id.bright2Sb);
        bright2Btn = (Button) findViewById(R.id.bright2Btn);
    }

    private void initData(){
        speedSb.setProgress(100);
        speedVCiBtn.setText(""+100+" 确定");
        windSpeedSb.setProgress(100);
        windSpeedBtn.setText(""+100+" 确定");
        hotSb.setProgress(40);
        hotValueBtn.setText(""+40+" 确定");
        PenTouSb.setProgress(180);
        PenTouBtn.setText(""+180+" 确定");
        PenTou2Sb.setProgress(180);
        PenTou2Btn.setText(""+180+" 确定");
        brightSb.setProgress(50);
        brightBtn.setText(""+50+" 确定");
        bright2Sb.setProgress(50);
        bright2Btn.setText(""+50+" 确定");
    }

    private void initAction(){
        speedSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                speedVCiBtn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        speedVCiBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = speedSb.getProgress();
                //发送
                EventBus.getDefault().post(speed+value);
            }
        });

        windSpeedSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                windSpeedBtn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        windSpeedBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = windSpeedSb.getProgress();
                //发送
                EventBus.getDefault().post(windSpeed+value);
            }
        });

        hotSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                hotValueBtn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        hotValueBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = hotSb.getProgress();
                //发送
                EventBus.getDefault().post(hot+value);
            }
        });

        PenTouSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                PenTouBtn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        PenTouBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = PenTouSb.getProgress();
                //发送
                EventBus.getDefault().post(penTou+value);
            }
        });

        PenTou2Sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                PenTou2Btn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        PenTou2Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = PenTou2Sb.getProgress();
                //发送
                EventBus.getDefault().post(penTou2+value);
            }
        });

        brightSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                brightBtn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });

        brightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = brightSb.getProgress();
                //发送
                EventBus.getDefault().post(bright+value);
            }
        });

        bright2Sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                bright2Btn.setText(""+progress+" 确定");
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        bright2Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int value = bright2Sb.getProgress();
                //发送
                EventBus.getDefault().post(bright2+value);
            }
        });

    }
}
